<template>
  <view>
    <view class="pay_success_logo">
      <image src="../../static/logo.png" mode="scaleToFill" />
      <view> 智慧聘 </view>
    </view>
	<view class="flexcenter">
		<button class="login_btn" @click="login_info">
		  <image src="../../static/wxicon.png"></image>快捷登录
		</button>
	</view>
    
    <!-- <button
      class="login_btn"
      open-type="getPhoneNumber"
      @getphonenumber="getPhoneNumber"
    >
      获取手机号
    </button> -->
  </view>
</template>

<script>
export default {
  data() {
    return {
      logo_url: "ss",
      code: "",
    };
  },
  onLoad() {
    this.getCode();
  },
  methods: {
    getCode() {
      console.log("获取code====");
      const that = this;
      uni.login({
        provider: "weixin",
        success: function (loginRes) {
          that.code = loginRes.code;
        },
      });
    },
    // getPhoneNumber(e) {
    //   console.log(e, "e");
    //   const data = {
    //     iv: e.detail.iv,
    //     encryptedData: e.detail.encryptedData,
    //   };
    //   console.log(data);
    //   //后端处理后返回解密的手机号码
    //   // this.login_info();
    // },
    login_info() {
      let that = this;
	  uni.showModal({
	  	title:'提示',
	  	content:'登录授权时需阅读小程序隐私保护指引',
	  	success(res) {
	  	    if(res.confirm){
	            uni.getUserProfile({
	             	lang:'zh_CN',
	             	desc: "用于登录后的信息绑定和显示",
	                success(res) {			
	                  uni.showToast({
	                    title: "授权成功",
	                    duration: 2000,
	                    icon: "success",
	                  });
	                  let paramData = {
	                   code: that.code,
	                   encryptedData: res.encryptedData,
	                   iv: res.iv,
	                 };
	                 that.login(paramData);
	               },
	               fail(err) {
	             	 console.log('===',err);
	                 uni.showToast({
	                   title: "您拒绝了授权",
	                   duration: 2000,
	                   icon: "error",
	                 });
	               },
	             });
	          }
	      }
	  })													
	  
      
    },
    login(paramData) {
      this.http.post("user/welogin", paramData)
	  .then((result) => {
        if (result.code == 1) {
			
          uni.setStorageSync("token", result.data.token);
		  uni.setStorageSync("userInfo", JSON.stringify(result));
		  
          uni.showToast({
            title: "登录成功",
            icon: "none",
          });
          setTimeout(() => {
            uni.reLaunch({
              url: "/pages/tabbar/tab-1",
            });
          }, 1000);
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.pay_success_logo {
  margin-top: 150rpx;
  display: flex;
  justify-content: center;
  flex-direction: column;
  align-items: center;
  color: #0396fd;
  font-size: 40rpx;
  color: #150e33;
  font-weight: 600;
  image {
    width: 200rpx;
    height: 200rpx;
    margin-bottom: 20rpx;
  }
}
.login_btn {
  margin-top: 400rpx;
  width: 686rpx;
  height: 98rpx;
  background-color: #1bd66c;
  display: flex;
  align-items: center;
  color: #fff;
  border-radius: 50rpx;
  justify-content: center;

  image {
    width: 55rpx;
    height: 44rpx;
    margin-right: 24rpx;
  }
}
</style>